package edu.zut.cs.software.perfect.course.web.spring.controller;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import edu.zut.cs.software.perfect.base.web.spring.controller.GenericController;
import edu.zut.cs.software.perfect.course.domain.CourseCategory;
import edu.zut.cs.software.perfect.course.service.CourseCategoryManager;
/**
 * @ClassName CourseCategoryController
 * @Description TODO
 * @Author liangying
 * @Date 2020年5月30日 上午12:21:01
 * @Version 1.0
 */

@Controller
@ResponseBody
@RequestMapping("/courseCategory")
public class CourseCategoryController extends GenericController<CourseCategory, Long, CourseCategoryManager> {

	CourseCategoryManager courseCategoryManager;
	
	@Autowired
	public void setCourseCategoryManager(CourseCategoryManager courseCategoryManager) {
		this.courseCategoryManager = courseCategoryManager;
		this.manager = this.courseCategoryManager;
	}
	
	
	/**
	 * The request is mapped to the parent class
	 * @return
	 */
//	@RequestMapping(method = RequestMethod.GET, value = "/index.html")
//    public String index() {
//        return "/courseCategory/index";
//    }
//	
//	@ResponseBody
//    @GetMapping(value = "hello", produces = "application/json;charset=utf-8")
//    public String hello() {
//        return "这里为课程类别信息！";
//    }
	
	//全查
	@ResponseBody
    @GetMapping(value = "findall", produces = "application/json;charset=utf-8")
    public String findAllCourseCategory() {
        List<CourseCategory> courseCategoryList = this.manager.findAll();
        PageInfo pageInfo = new PageInfo(courseCategoryList);
        return JSON.toJSONString(pageInfo);
    }
	
	@GetMapping("/findbyid/{id}")
	public String fingById(@PathVariable("id") Long id) {
		Optional<CourseCategory> result = this.manager.findByCourseId(id);
		return JSON.toJSONString(result);
	}
	
}
